package cool.tianyou.blue.bird.config;

import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;

/**
 * @author Liutianyou
 * @date 2021/8/14 9:53 下午
 */
@Configuration
public class JmConfig {
  @Value("${spring.activemq.user}")
  private String user;
  @Value("${spring.activemq.password}")
  private String password;
  @Value("${spring.activemq.broker-url}")
  private String brokerUrl;
  @Bean
  ConnectionFactory connectionFactory() {
    return new ActiveMQConnectionFactory(user,password,brokerUrl);
  }

  @Bean
  JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setPriority(999);
    return jmsTemplate;
  }

  @Bean(value="jmsMessagingTemplate")
  JmsMessagingTemplate jmsMessagingTemplate(JmsTemplate jmsTemplate) {
    return new JmsMessagingTemplate(jmsTemplate);
  }
}
